package com.hsnn.medstgmini.base.dict.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.base.dict.dao.DicCompTypeLogDao;
import com.hsnn.medstgmini.base.dict.model.DicCompTypeLog;
import com.hsnn.medstgmini.base.dict.service.DicCompTypeLogManager;
import com.hsnn.medstgmini.model.Result;
import com.hsnn.medstgmini.util.Pagination;

@SuppressWarnings("deprecation")
@Service
public class DicCompTypeLogManagerImpl implements DicCompTypeLogManager {
	
	@Autowired
	private DicCompTypeLogDao dicCompTypeLogDao;

	@Override
	public List<DicCompTypeLog> dicCompTypeLogList(Result result,
			DicCompTypeLog dicCompTypeLog) {
		return dicCompTypeLogDao.dicCompTypeLogList(result, dicCompTypeLog);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getDicCompTypeLogList(Pagination page){
		List<Map<String,Object>> oldList = (List<Map<String, Object>>) dicCompTypeLogDao.getDicCompTypeLogList(page).getRows();
		List<Map<String,Object>> newList = new ArrayList<Map<String,Object>>();
		if(oldList!=null&&oldList.size()>0){
			for(int i = 0;i<oldList.size();i++){
				StringBuffer newDetail = new StringBuffer();
				if(oldList.get(i).get("detail")!=null){
					String details = oldList.get(i).get("detail").toString();
					if(details.split(";")[0].split(",").length==2){
						newDetail.append("<br/>新增数据");
					}
					String[] detail = details.split(";");
					for(int j = 0;j<detail.length;j++){
						String[] data = detail[j].split(",");
						if(data.length==2){
							newDetail.append("<br/>")
							         .append(data[0])
							         .append(":")
							         .append(data[1]);
						}else{
							newDetail.append("<br/>")
							         .append(data[0])
							         .append("由")
							         .append(data[2])
							         .append("变为")
							         .append(data[1]);
						}
						
						
					}
					newDetail.delete(0, 5);
					oldList.get(i).put("detail", newDetail.toString());
				}
				
				newList.add(oldList.get(i));
			}
			page.setRows(newList);
		}
		return page;
	}

	/**
	 * 基础库 数据字典 企业注册类型维护记录 日志详情
	 * @param page
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getDicCompTypeLogDetail(Pagination page) {
		return dicCompTypeLogDao.getDicCompTypeLogDetail(page);
	}

}
